package com.batchengine.worker;

import com.batchengine.task.TaskContext;
import com.batchengine.util.LoggingFactory;
import static com.batchengine.worker.WorkerType.WORK_GATHERER;
import org.apache.log4j.Logger;

/**
 * Created by sunil.incubator@yahoo.com.
 * User: sunil.kalva
 * Date: Jul 10, 2009
 */
public class DataGatherer<T> extends Worker {

    private static final Logger logger = LoggingFactory.createLogger();
    protected WorkSelector<T> workSelector;

    public DataGatherer(String name, long taskId, WorkSelector<T> workSelector) {
        super(name, taskId);
        this.workSelector = workSelector;
    }

    public WorkSelector<T> getWorkSelector() {
        return workSelector;
    }

    public WorkerType getType() {
        return WORK_GATHERER;
    }

    protected void doWork(TaskContext context) {

        try {
            workSelector.fillWork();
        } catch (InterruptedException e) {
            logger.error("error@DataGatherer#doWork", e);
        }
    }

    @Override
    public String toString() {
        return "DataGatherer{" +
                "status = " + getStatus() +
                "workSelector=" + workSelector +
                '}';
    }
}
